package com.ssm.dao;

import com.ssm.bean.User;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * 用户的持久层
 */
public interface IUserDao {

    //查询所有用户
    @Select("select * from user")
    @Results(id = "userMap",value = {
            @Result(id = true, column = "id", property = "userId"),
            @Result(column = "username", property = "userName"),
            @Result(column = "address", property = "userAddress"),
            @Result(column = "sex", property = "userSex"),
            @Result(column = "birthday", property = "userBirthday"),
            @Result(column = "id",property = "accounts",many = @Many(select = "com.ssm.dao.IAccountDao.getAccountByUid",fetchType= FetchType.LAZY))
    })
    public List<User> findAll();

    //查询用户根据id

    @Select("select * from user where id = #{id}")
    @ResultMap("userMap")
    public User getUserById(Integer id);



}
